package com.gitee.xhs.dao;

import cn.hutool.core.date.DateUtil;

import java.util.Date;

/**
 * @author BigHead
 * @date 2022/7/13 17:23
 * @description WatermarkRecordDao
 */
public class WatermarkRecordDao<T> {

    private final String watermarkStrategyType;
    private final String watermarkGeneratorType;
    private final String watermarkAssignerType;
    private T record;
    private Long systemCurrentTimeMillis;
    private Long streamRecordTimestamp;
    private Long timeServiceCurrentWatermark;
    private Long timeServiceProcessingTime;

    public WatermarkRecordDao(String watermarkStrategyType, String watermarkGeneratorType, String watermarkAssignerType) {
        this.watermarkStrategyType = watermarkStrategyType;
        this.watermarkGeneratorType = watermarkGeneratorType;
        this.watermarkAssignerType = watermarkAssignerType;
    }

    public T getRecord() {
        return record;
    }

    public void setRecord(T record) {
        this.record = record;
    }

    public Long getSystemCurrentTimeMillis() {
        return systemCurrentTimeMillis;
    }

    public void setSystemCurrentTimeMillis(Long systemCurrentTimeMillis) {
        this.systemCurrentTimeMillis = systemCurrentTimeMillis;
    }

    public Long getStreamRecordTimestamp() {
        return streamRecordTimestamp;
    }

    public void setStreamRecordTimestamp(Long streamRecordTimestamp) {
        this.streamRecordTimestamp = streamRecordTimestamp;
    }

    public Long getTimeServiceCurrentWatermark() {
        return timeServiceCurrentWatermark;
    }

    public void setTimeServiceCurrentWatermark(Long timeServiceCurrentWatermark) {
        this.timeServiceCurrentWatermark = timeServiceCurrentWatermark;
    }

    public Long getTimeServiceProcessingTime() {
        return timeServiceProcessingTime;
    }

    public void setTimeServiceProcessingTime(Long timeServiceProcessingTime) {
        this.timeServiceProcessingTime = timeServiceProcessingTime;
    }

    @Override
    public String toString() {
        String systemCurrentTimeMillisString = null == systemCurrentTimeMillis ? "noTime" : DateUtil.formatDateTime(new Date(systemCurrentTimeMillis));
        String streamRecordTimestampString = null == streamRecordTimestamp ? "noTime" : DateUtil.formatDateTime(new Date(streamRecordTimestamp));
        String timeServiceCurrentWatermarkString = null == timeServiceCurrentWatermark ? "noTime" : DateUtil.formatDateTime(new Date(timeServiceCurrentWatermark));
        String timeServiceProcessingTimeString = null == timeServiceProcessingTime ? "noTime" : DateUtil.formatDateTime(new Date(timeServiceProcessingTime));

        return "WATER_MARK_STRATEGY_TYPE[" + watermarkStrategyType + "] WATER_MARK_GENERATOR_TYPE[" + watermarkGeneratorType + "],WATER_MARK_ASSIGNER_TYPE[" + watermarkAssignerType + "]\n" +
                "WatermarkRecordDao{\n" +
                "    record=" + record + "\n" +
                "    系统时间=" + systemCurrentTimeMillis +
                ", 系统时间='" + systemCurrentTimeMillisString + "'\n" +
                "    Flink-TimestampAssigner-时间=" + streamRecordTimestamp +
                ", Flink-TimestampAssigner-时间='" + streamRecordTimestampString + "'\n" +
                "    Flink-WatermarkGenerator-时间=" + timeServiceCurrentWatermark +
                ", Flink-WatermarkGenerator-时间=" + timeServiceCurrentWatermarkString + "'\n" +
                "    Flink-currentProcessingTime=" + timeServiceProcessingTime +
                ", Flink-currentProcessingTime=" + timeServiceProcessingTimeString + "'\n" +
                '}';
    }

}
